home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / Xprof / xmeasure / tstgfx.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  20KB  |  849 lines

  1. /*==================================================================
  2.  *      File :          tstgfx.c
  3.  *      Package:        Xmeasure
  4.  * 
  5.  *      Author :        Aloke Gupta.
  6.  *
  7.  *  (C) Copyright 1992, Aloke Gupta.
  8.  *  All rights granted to University of Illinois Board of Regents.
  9.  *==================================================================*/
  10.  
  11. #include "perf.h"
  12.  
  13. #define POLYOBJECTS 8     /* Number of objects for Poly requests */
  14.  
  15. #define XINC_LINE 64
  16. #define YINC_LINE 64
  17.  
  18. #define XINC_RECT  1
  19. #define YINC_RECT  2
  20.  
  21. #define XOFFSET_RECT 2
  22. #define YOFFSET_RECT 2
  23.  
  24. /* Shared variables */
  25. static int i;
  26. static XPoint     *points;
  27. static XSegment   *segments;
  28. static XRectangle *rectangles;
  29. static XArc      *arcs;
  30. static XImage      *image;
  31. static Pixmap       pixmap;
  32. static Pixmap      *pixmaps;
  33. static GC       mygc;
  34. static GC      *GCs;
  35. static XGCValues   gcval;
  36. static unsigned long gcmask;
  37.  
  38. /* ====================================================================== */
  39.  
  40. int   CreatePixmap(xd, xp)   
  41. XD *xd;
  42. XParams *xp;
  43. {
  44.     int width = 16, height = 16;
  45.     for (i = 0; i < xp->itns; i++) {
  46.     pixmaps[i] = XCreatePixmap(xd->display, xd->window, width, height,
  47.             DefaultDepth(xd->display, xd->screen ));
  48.     if (pixmaps[i] == NULL) {
  49.     /*
  50.         fprintf(stderr, "CreatePixmap: Can't allocate %dth pixmap", i);
  51.     */
  52.         xp->itns = i;
  53.         break;
  54.     }
  55.     }
  56. }
  57. int i_CreatePixmap(xd, xp)   
  58. XD *xd;
  59. XParams *xp;
  60. {
  61.     pixmaps = (Pixmap *) malloc (xp->itns * sizeof(Pixmap));
  62. }
  63. int c_CreatePixmap(xd, xp)   
  64. XD *xd;
  65. XParams *xp;
  66. {
  67.     for (i = 0; i < xp->itns; i++)
  68.     XFreePixmap(xd->display, pixmaps[i]);
  69.     free(pixmaps);
  70. }
  71.  
  72. /* ====================================================================== */
  73.  
  74. int   FreePixmap(xd, xp)     
  75. XD *xd;
  76. XParams *xp;
  77. {
  78.     for (i = 0; i < xp->itns; i++)
  79.     XFreePixmap(xd->display, pixmaps[i]);
  80. }
  81. int i_FreePixmap(xd, xp)     
  82. XD *xd;
  83. XParams *xp;
  84. {
  85.     int width = 8, height = 8;
  86.     pixmaps = (Pixmap *) malloc (xp->itns * sizeof(Pixmap));
  87.     for (i = 0; i < xp->itns; i++) {
  88.     pixmaps[i] = XCreatePixmap(xd->display, xd->window, width, height,
  89.             DefaultDepth(xd->display, xd->screen ));
  90.     if (pixmaps[i] == NULL) {
  91.         /*
  92.         fprintf(stderr, "Can't allocate %dth pixmap", i);
  93.         */
  94.         xp->itns = i;
  95.         break;
  96.     }
  97.     }
  98. }
  99. int c_FreePixmap(xd, xp)     
  100. XD *xd;
  101. XParams *xp;
  102. {
  103.     free(pixmaps);
  104. }
  105.  
  106. /* ====================================================================== */
  107.  
  108. int   CreateGC(xd, xp)       
  109. XD *xd;
  110. XParams *xp;
  111. {
  112.     for (i = 0; i < xp->itns; i++)
  113.     GCs[i] = XCreateGC(xd->display, xd->window, gcmask, &gcval);
  114. }
  115.  
  116. int i_CreateGC(xd, xp)       
  117. XD *xd;
  118. XParams *xp;
  119. {
  120.     GCs = (GC *) malloc(xp->itns * sizeof(GC));
  121.     gcmask = GCFunction | GCLineWidth | GCLineStyle | GCFillStyle;
  122.     gcval.function   = GXxor;
  123.     gcval.line_width = 1;
  124.     gcval.line_style = LineOnOffDash;
  125.     gcval.fill_style = FillStippled;
  126.  
  127. }
  128.  
  129. int c_CreateGC(xd, xp)       
  130. XD *xd;
  131. XParams *xp;
  132. {
  133.     for (i = 0; i < xp->itns; i++)
  134.     XFreeGC(xd->display, GCs[i]);
  135.     free(GCs);
  136. }
  137.  
  138. /* ====================================================================== */
  139. /* Note: XChangeGC measurement is meaningless since Xlib has a cache for GC
  140.      attributes.
  141.  */
  142. int   ChangeGC(xd, xp)       
  143. XD *xd;
  144. XParams *xp;
  145. {
  146.     for (i = 0; i < xp->itns; i++) {
  147.     if (i % 2) gcval.function = GXcopy;
  148.     else       gcval.function   = GXxor;
  149.     XChangeGC(xd->display, mygc, gcmask, &gcval);
  150.     }
  151. }
  152.  
  153. int i_ChangeGC(xd, xp)       
  154. XD *xd;
  155. XParams *xp;
  156. {
  157.     mygc = XCreateGC(xd->display, xd->window, 0, 0);
  158.     gcmask = GCFunction | GCLineWidth  | GCLineStyle | GCFillStyle |
  159.               GCForeground | GCBackground;
  160.     gcval.function   = GXxor;
  161.     gcval.line_width = 1;
  162.     gcval.line_style = LineOnOffDash;
  163.     gcval.fill_style = FillStippled;
  164.     gcval.foreground = WhitePixel(xd->display, xd->screen);
  165.     gcval.background = BlackPixel(xd->display, xd->screen);
  166. }
  167.  
  168. int c_ChangeGC(xd, xp)       
  169. XD *xd;
  170. XParams *xp;
  171. {
  172.     XFreeGC(xd->display, mygc);
  173. }
  174.  
  175. /* ====================================================================== */
  176.  
  177. int   CopyGC(xd, xp)         
  178. XD *xd;
  179. XParams *xp;
  180. {
  181.     for (i = 0; i < xp->itns; i++)
  182.     XCopyGC(xd->display, GCs[0], gcmask, GCs[1]);
  183. }
  184.  
  185. int i_CopyGC(xd, xp)         
  186. XD *xd;
  187. XParams *xp;
  188. {    
  189.     GCs = (GC *) malloc(2 * sizeof(GC)); 
  190.     GCs[0] = XCreateGC(xd->display, xd->window, 0, 0);
  191.     GCs[1] = XCreateGC(xd->display, xd->window, 0, 0);
  192.     gcmask = ~0;    /* Worst case: Copy all the attributes */
  193.  
  194.     gcmask = GCFunction | GCLineWidth  | GCLineStyle | GCFillStyle |
  195.               GCForeground | GCBackground;
  196. }
  197.  
  198. int c_CopyGC(xd, xp)         
  199. XD *xd;
  200. XParams *xp;
  201. {
  202.     XFreeGC(xd->display, GCs[0]);
  203.     XFreeGC(xd->display, GCs[1]);
  204.     free(GCs);
  205. }
  206.  
  207. /* ====================================================================== */
  208.  
  209. int   SetDashes(xd, xp)      
  210. XD *xd;
  211. XParams *xp;
  212. {
  213.     static char dash2[] = {6, 3};
  214.     static char dash4[] = {9, 3, 3, 3};
  215.  
  216.     for (i = 0; i < xp->itns; i++) {
  217.     if (i % 2) XSetDashes(xd->display, mygc, 0, dash2, 2);
  218.     else       XSetDashes(xd->display, mygc, 0, dash4, 4);
  219.     }
  220. }
  221. int i_SetDashes(xd, xp)      
  222. XD *xd;
  223. XParams *xp;
  224. {   mygc = XCreateGC(xd->display, xd->window, 0, 0); }
  225. int c_SetDashes(xd, xp)      
  226. XD *xd;
  227. XParams *xp;
  228. {   XFreeGC(xd->display, mygc); }
  229.  
  230. /* ====================================================================== */
  231. static XRectangle crect4[4];
  232.  
  233. int   SetClipRectangles(xd, xp)
  234. XD *xd;
  235. XParams *xp;
  236. {
  237.     for (i = 0; i < xp->itns; i++) {
  238.     if (i % 2)
  239.          XSetClipRectangles(xd->display, mygc, 0, 0, crect4, 2, Unsorted);
  240.     else XSetClipRectangles(xd->display, mygc, 0, 0, crect4, 4, Unsorted);
  241.     }
  242. }
  243.  
  244. int i_SetClipRectangles(xd, xp)
  245. XD *xd;
  246. XParams *xp;
  247. {
  248.     mygc = XCreateGC(xd->display, xd->window, 0, 0);
  249.     for (i = 0; i < 4; i++) {
  250.     crect4[i].x     = DISPWIDTH  / (i + 1);
  251.     crect4[i].y     = DISPHEIGHT / (i + 1);
  252.     crect4[i].width  = DISPWIDTH  / (i + 1);
  253.     crect4[i].height = DISPHEIGHT / (i + 1);
  254.     }
  255. }
  256.  
  257. int c_SetClipRectangles(xd, xp)
  258. XD *xd;
  259. XParams *xp;
  260. {   XFreeGC(xd->display, mygc); }
  261.  
  262. /* ====================================================================== */
  263.  
  264. int   FreeGC(xd, xp)         
  265. XD *xd;
  266. XParams *xp;
  267. {
  268.     for (i = 0; i < xp->itns; i++)
  269.     XFreeGC(xd->display, GCs[i]);
  270. }
  271.  
  272. int i_FreeGC(xd, xp)         
  273. XD *xd;
  274. XParams *xp;
  275. {
  276.     GCs = (GC *) malloc(xp->itns * sizeof(GC));
  277.     for (i = 0; i < xp->itns; i++)
  278.     GCs[i] = XCreateGC(xd->display, xd->window, 0, 0);
  279.  
  280. int c_FreeGC(xd, xp)         
  281. XD *xd;
  282. XParams *xp;
  283. {
  284.     free(GCs);
  285. }
  286.  
  287. /* ====================================================================== */
  288. /* ClearArea: Sizepair => (width, height)     */
  289. /*           size     => area = width * height       */
  290.  
  291. int   ClearArea(xd, xp)      
  292. XD *xd;
  293. XParams *xp;
  294. {
  295.     int width, height;
  296.  
  297.     width    = xp->sizepair->s1;
  298.     height   = xp->sizepair->s2;
  299.     xp->size = width * height; 
  300.  
  301.     for (i = 0; i < xp->itns; i++)
  302.     XClearArea(xd->display, xd->window, 0, 0, width, height, True);
  303. }
  304.  
  305. int i_ClearArea(xd, xp)      
  306. XD *xd;
  307. XParams *xp;
  308. {
  309.     XFillRectangle(xd->display, xd->window, xd->gc, 0, 0,
  310.             DISPWIDTH, DISPHEIGHT);
  311.     xp->size = xp->sizepair->s1 * xp->sizepair->s2;
  312. }
  313.  
  314. int c_ClearArea(xd, xp)      
  315. XD *xd;
  316. XParams *xp;
  317. {
  318. }
  319.  
  320. /* ====================================================================== */
  321. /* CopyArea: Sizepair => (width, height)             */
  322. /*          size     => area = width * height        */
  323. /* The code here only measures the time taken to copy from pixmap to window */
  324.  
  325. int   CopyArea(xd, xp)       
  326. XD *xd;
  327. XParams *xp;
  328. {
  329.     int width, height;
  330.     int dst_x = 0, dst_y = 0;
  331.  
  332.     width  = xp->sizepair->s1;
  333.     height = xp->sizepair->s2;
  334.     for (i = 0; i < xp->itns; i++) {
  335.     XCopyArea(xd->display, pixmap, xd->window, xd->gc, 0, 0,
  336.             width, height, dst_x, dst_y);
  337.     if (height < DISPHEIGHT / 2)
  338.         dst_y += height;
  339.     else dst_y ++;
  340.     if ((dst_y + height) > DISPHEIGHT) {
  341.         dst_y %= DISPHEIGHT;
  342.         dst_x ++;
  343.         if ((dst_x + width ) > DISPWIDTH )
  344.         dst_x %= DISPWIDTH;
  345.     }
  346.     }
  347. }
  348.  
  349. int i_CopyArea(xd, xp)       
  350. XD *xd;
  351. XParams *xp;
  352. {
  353.     int width, height;
  354.  
  355.     width    = xp->sizepair->s1;
  356.     height   = xp->sizepair->s2;
  357.     xp->size = width * height;
  358.     RandomFill(xd, xp);
  359.     pixmap   = XCreatePixmap(xd->display, xd->window, width, height,
  360.             DefaultDepth(xd->display, xd->screen ));
  361.     XCopyArea(xd->display, xd->window, pixmap, xd->gc, 0, 0,
  362.             width, height, 0, 0);
  363. }
  364.  
  365. int c_CopyArea(xd, xp)       
  366. XD *xd;
  367. XParams *xp;
  368. {
  369.     XFreePixmap(xd->display, pixmap);
  370.     XClearWindow(xd->display, xd->window);
  371. }
  372.  
  373. /* ====================================================================== */
  374. /* CopyPlane: Sizepair => (width, height)                */
  375. /*            size     => area = width * height          */
  376.  
  377. int   CopyPlane(xd, xp)      
  378. XD *xd;
  379. XParams *xp;
  380. {
  381.     int width, height;
  382.     int dst_x = 0, dst_y = 0;
  383.  
  384.     width  = xp->sizepair->s1;
  385.     height = xp->sizepair->s2;
  386.     for (i = 0; i < xp->itns; i++) {
  387.     XCopyPlane(xd->display, pixmap, xd->window, xd->gc, 0, 0,
  388.             width, height, dst_x, dst_y, 1);
  389.     if (height < DISPHEIGHT / 2)
  390.         dst_y += height;
  391.     else dst_y ++;
  392.     if ((dst_y + height) > DISPHEIGHT) {
  393.         dst_y %= DISPHEIGHT;
  394.         dst_x ++;
  395.         if ((dst_x + width ) > DISPWIDTH )
  396.         dst_x %= DISPWIDTH;
  397.     }
  398.     }
  399. }
  400.  
  401. int i_CopyPlane(xd, xp)      
  402. XD *xd;
  403. XParams *xp;
  404. {
  405.     int width, height;
  406.  
  407.     width    = xp->sizepair->s1;
  408.     height   = xp->sizepair->s2;
  409.     xp->size = width * height;
  410.     RandomFill(xd, xp);
  411.     pixmap   = XCreatePixmap(xd->display, xd->window, width, height, 1);
  412. }
  413.  
  414. int c_CopyPlane(xd, xp)      
  415. XD *xd;
  416. XParams *xp;
  417. {
  418.     XFreePixmap(xd->display, pixmap);
  419.     XClearWindow(xd->display, xd->window);
  420. }
  421.  
  422. /* ====================================================================== */
  423. /* PolyPoint: Sizepair => (0, 0) */
  424.  
  425. int   PolyPoint(xd, xp)      
  426. XD *xd;
  427. XParams *xp;
  428. {
  429.     for (i = 0; i < xp->itns; i++)
  430.     XDrawPoints(xd->display, xd->window, xp->gc, 
  431.         points, (int) xp->numobjs, CoordModeOrigin);
  432. }
  433.  
  434. int i_PolyPoint(xd, xp)
  435. XD *xd;
  436. XParams *xp;
  437. {
  438.     xp->size = 0;
  439.     xp->numobjs = POLYOBJECTS;
  440.     points = (XPoint *) malloc(xp->numobjs * sizeof(XPoint) );
  441.  
  442.     for (i = 0; i < xp->numobjs; i++) {
  443.         points[i].x = rand() % DISPWIDTH;
  444.         points[i].y = rand() % DISPHEIGHT;
  445.     }
  446. }
  447.  
  448. int c_PolyPoint(xd, xp)
  449. XD *xd;
  450. XParams *xp;
  451. {
  452.     free(points);
  453. }
  454.  
  455. /* ====================================================================== */
  456. /* PolyLine: Sizepair => (length, 0) */
  457.  
  458. int   PolyLine(xd, xp)
  459. XD *xd;
  460. XParams *xp;
  461. {
  462.     for (i = 0; i < xp->itns; i++)
  463.         XDrawLines(xd->display,xd->window, xp->gc, points,
  464.             (int) xp->numobjs, CoordModeOrigin);
  465. }
  466.  
  467. int i_PolyLine(xd, xp) 
  468. XD *xd;
  469. XParams *xp;
  470. {
  471.     int xoffset = XINC_LINE / 2;
  472.     int yoffset = YINC_LINE / 2;
  473.     int xdir=1, ydir=1;
  474.  
  475.     xp->size = xp->sizepair->s1;    /* Length of line */
  476.     xp->numobjs = POLYOBJECTS;        /* Number of objects per request */
  477.     points = (XPoint *) malloc((xp->numobjs + 1 )* sizeof(XPoint));
  478.  
  479.     for (i = 0; i < xp->numobjs; i+=2) {
  480.         points[i].x   = xoffset ;
  481.         points[i].y   = yoffset ;
  482.  
  483.         points[i+1].x = xoffset + (xdir * xp->size);
  484.         points[i+1].y = yoffset + (ydir * YINC_LINE);
  485.  
  486.     /* Now set xoffset and yoffset for next computation */
  487.     yoffset += ydir * YINC_LINE;
  488.     if ((yoffset >= (DISPHEIGHT - YINC_LINE) ) || (yoffset <= YINC_LINE)) {
  489.         /* y has hit an extreme. */
  490.         ydir    *= -1;
  491.         xoffset += xdir * 2 * xp->size;/* Move away from previous drawing */
  492.  
  493.         if ( (xoffset >= (DISPWIDTH - XINC_LINE - xp->size)) ||
  494.          (xoffset <= XINC_LINE) )        {
  495.         xdir   *= -1;
  496.         xoffset+=xdir * 2 * xp->size;/*undo the last change to xoffset*/
  497.         if (xoffset <= (XINC_LINE + xp->size) )
  498.             xdir *= -1;
  499.         }
  500.     }
  501.     }
  502. }
  503.  
  504. int c_PolyLine(xd, xp) 
  505. XD *xd;
  506. XParams *xp;
  507. {
  508.     free(points);
  509. }
  510.  
  511. /* ====================================================================== */
  512. /* PolySegment: Sizepair => (length, 0) */
  513.  
  514. int   PolySegment(xd, xp)    
  515. XD *xd;
  516. XParams *xp;
  517. {
  518.     for (i = 0; i < xp->itns; i++) 
  519.     XDrawSegments(xd->display,xd->window, xp->gc,
  520.         segments, (int) xp->numobjs);
  521. }
  522. int i_PolySegment(xd, xp)    
  523. XD *xd;
  524. XParams *xp;
  525. {
  526.     int xoffset = XINC_LINE / 2;
  527.     int yoffset = YINC_LINE / 2;
  528.     int xdir=1, ydir=1;
  529.  
  530.     xp->size = xp->sizepair->s1;
  531.     xp->numobjs = POLYOBJECTS;
  532.     segments = (XSegment *) malloc((xp->numobjs + 1 )* sizeof(XSegment));
  533.  
  534.     for (i = 0; i < xp->numobjs; i++) {
  535.         segments[i].x1 = xoffset ;
  536.         segments[i].y1 = yoffset ;
  537.  
  538.         segments[i].x2 = xoffset + (xdir * xp->size);
  539.         segments[i].y2 = yoffset + (ydir * YINC_LINE);
  540.  
  541.     /* Now set xoffset and yoffset for next computation */
  542.     yoffset += ydir * YINC_LINE;
  543.     if ((yoffset >= (DISPHEIGHT - YINC_LINE) ) || (yoffset <= YINC_LINE)) {
  544.         /* y has hit an extreme. */
  545.         ydir    *= -1;
  546.         xoffset += xdir * 2 * xp->size;/* Move away from previous drawing */
  547.  
  548.         if ( (xoffset >= (DISPWIDTH - XINC_LINE - xp->size)) ||
  549.          (xoffset <= XINC_LINE) )        {
  550.         xdir   *= -1;
  551.         xoffset+=xdir * 2 * xp->size;/*undo the last change to xoffset*/
  552.         if (xoffset <= (XINC_LINE + xp->size) )
  553.             xdir *= -1;
  554.         }
  555.     }
  556.     }
  557. }
  558.  
  559. int c_PolySegment(xd, xp)    
  560. XD *xd;
  561. XParams *xp;
  562. {
  563.     free(segments);
  564. }
  565.  
  566. /* ====================================================================== */
  567. /* PolyRectangle: Sizepair => (width, height)             */
  568. /*           size     => perimeter = 2 * (width + height)    */
  569.  
  570. int   PolyRectangle(xd, xp)  
  571. XD *xd;
  572. XParams *xp;
  573. {
  574.     for (i = 0; i < xp->itns; i++)
  575.     XDrawRectangles(xd->display, xd->window, xp->gc,
  576.         rectangles, (int) xp->numobjs);
  577. }
  578.  
  579. int i_PolyRectangle(xd, xp)  
  580. XD *xd;
  581. XParams *xp;
  582. {
  583.     int xoffset = XOFFSET_RECT;
  584.     int yoffset = YOFFSET_RECT;
  585.     int xdir = 1, ydir = 1;
  586.     int width, height;
  587.  
  588.     width    = xp->sizepair->s1;
  589.     height    = xp->sizepair->s2;
  590.     xp->size    = 2 * (width + height);
  591.     xp->numobjs = POLYOBJECTS;
  592.     rectangles  = (XRectangle *) malloc (xp->numobjs * sizeof(XRectangle));
  593.  
  594.     for (i = 0; i < xp->numobjs; i++) {
  595.     rectangles[i].x      = xoffset;
  596.     rectangles[i].y      = yoffset;
  597.     rectangles[i].width  = width;
  598.     rectangles[i].height = height;
  599.  
  600.     yoffset += ydir * YINC_RECT;
  601.     xoffset += xdir * XINC_RECT;
  602.  
  603.     if ( (xoffset >= (DISPHEIGHT - width)) || (xoffset <= XINC_RECT) ) {
  604.         xdir *= -1;
  605.         xoffset += xdir * (XINC_RECT + 1);
  606.     }
  607.     if ( (yoffset >= (DISPHEIGHT - height)) || (yoffset <= YINC_RECT) ) {
  608.         ydir *= -1;
  609.         yoffset += ydir * (YINC_RECT + 1);
  610.     }
  611.     }
  612. }
  613.  
  614. int c_PolyRectangle(xd, xp)  
  615. XD *xd;
  616. XParams *xp;
  617. {
  618.     free(rectangles);
  619. }
  620.  
  621. /* ====================================================================== */
  622. /* PolyArc: Sizepair => (width, height)             */
  623. /*         size     => perimeter = 2 * (width + height)    */
  624. /* Fractional arcs are scaled from the data collected here    */
  625.  
  626. int   PolyArc(xd, xp)        
  627. XD *xd;
  628. XParams *xp;
  629. {
  630.     for (i = 0; i < xp->itns; i++)
  631.     XDrawArcs(xd->display, xd->window, xp->gc,
  632.         arcs, (int) xp->numobjs);
  633. }
  634.  
  635. int i_PolyArc(xd, xp)        
  636. XD *xd;
  637. XParams *xp;
  638. {
  639.     int xoffset = XOFFSET_RECT;
  640.     int yoffset = YOFFSET_RECT;
  641.     int xdir = 1, ydir = 1;
  642.     int width, height;
  643.  
  644.     width    = xp->sizepair->s1;
  645.     height    = xp->sizepair->s2;
  646.     xp->size    = 2 * (width + height);
  647.     xp->numobjs = POLYOBJECTS;
  648.     arcs    = (XArc *) malloc (xp->numobjs * sizeof(XArc));
  649.  
  650.     for (i = 0; i < xp->numobjs; i++) {
  651.     arcs[i].x      = xoffset;
  652.     arcs[i].y      = yoffset;
  653.     arcs[i].width  = width;
  654.     arcs[i].height = height;
  655.     arcs[i].angle1 = 0;
  656.     arcs[i].angle2 = 64 * 360;    /* Full circle */
  657.  
  658.     yoffset += ydir * YINC_RECT;
  659.     xoffset += xdir * XINC_RECT;
  660.  
  661.     if ( (xoffset >= (DISPHEIGHT - width)) || (xoffset <= XINC_RECT) ) {
  662.         xdir *= -1;
  663.         xoffset += xdir * (XINC_RECT + 1);
  664.     }
  665.     if ( (yoffset >= (DISPHEIGHT - height)) || (yoffset <= YINC_RECT) ) {
  666.         ydir *= -1;
  667.         yoffset += ydir * (YINC_RECT + 1);
  668.     }
  669.     }
  670. }
  671.  
  672. int c_PolyArc(xd, xp)        
  673. XD *xd;
  674. XParams *xp;
  675. {
  676.     free(arcs);
  677. }
  678.  
  679. /* ====================================================================== */
  680.  
  681. int   FillPoly(xd, xp)       
  682. XD *xd;
  683. XParams *xp;
  684. {
  685. }
  686. int i_FillPoly(xd, xp)       
  687. XD *xd;
  688. XParams *xp;
  689. {
  690. }
  691. int c_FillPoly(xd, xp)       
  692. XD *xd;
  693. XParams *xp;
  694. {
  695. }
  696.  
  697. /* ====================================================================== */
  698. /* PolyFillRectangle: Sizepair => (width, height)     */
  699. /*               size     => area = width * height    */
  700.  
  701. int   PolyFillRectangle(xd, xp)
  702. XD *xd;
  703. XParams *xp;
  704. {
  705.     for (i = 0; i < xp->itns; i++)
  706.     XFillRectangles(xd->display, xd->window, xp->gc,
  707.         rectangles, (int) xp->numobjs);
  708. }
  709. int i_PolyFillRectangle(xd, xp)
  710. XD *xd;
  711. XParams *xp;
  712. {
  713.     i_PolyRectangle(xd, xp);
  714.     xp->size = xp->sizepair->s1 * xp->sizepair->s2;
  715. }
  716. int c_PolyFillRectangle(xd, xp)
  717. XD *xd;
  718. XParams *xp;
  719. {
  720.     c_PolyRectangle(xd, xp);
  721. }
  722.  
  723. /* ====================================================================== */
  724. /* PolyFillArc: Sizepair => (width, height)     */
  725. /*        size     => area = width * height    */
  726. /* Fractional arcs are scaled from the data collected here    */
  727.  
  728. int   PolyFillArc(xd, xp)    
  729. XD *xd;
  730. XParams *xp;
  731. {
  732.     for (i = 0; i < xp->itns; i++)
  733.     XFillArcs(xd->display, xd->window, xp->gc, arcs, (int) xp->numobjs);
  734. }
  735.  
  736. int i_PolyFillArc(xd, xp)    
  737. XD *xd;
  738. XParams *xp;
  739. {
  740.     i_PolyArc(xd, xp);
  741.     xp->size = xp->sizepair->s1 * xp->sizepair->s2;
  742. }
  743.  
  744. int c_PolyFillArc(xd, xp)    
  745. XD *xd;
  746. XParams *xp;
  747. {
  748.     c_PolyArc(xd, xp);
  749. }
  750.  
  751. /* ====================================================================== */
  752. /* PutImage: Sizepair => (width, height)     */
  753. /*          size     => area = width * height       */
  754.  
  755. int   PutImage(xd, xp)       
  756. XD *xd;
  757. XParams *xp;
  758. {
  759.     int width, height;
  760.     int dst_x = 0, dst_y = 0;
  761.  
  762.     width  = xp->sizepair->s1;
  763.     height = xp->sizepair->s2;
  764.     for (i = 0; i < xp->itns; i++) {
  765.     XPutImage(xd->display, xd->window, xp->gc, image,
  766.             0, 0, dst_x, dst_y, width, height);
  767.     dst_x ++; dst_y ++;
  768.     if ((dst_x + width ) > DISPWIDTH ) dst_x = 0;
  769.     if ((dst_y + height) > DISPHEIGHT) dst_y = 0;
  770.     }
  771. }
  772.  
  773. int i_PutImage(xd, xp)       
  774. XD *xd;
  775. XParams *xp;
  776. {
  777.     xp->size = xp->sizepair->s1 * xp->sizepair->s2;
  778.     RandomFill(xd, xp);
  779.     /* Create an image */
  780.     image = XGetImage(xd->display, xd->window, 0, 0,
  781.             DISPWIDTH, DISPHEIGHT, ~0, ZPixmap);
  782. }
  783.  
  784. int c_PutImage(xd, xp)       
  785. XD *xd;
  786. XParams *xp;
  787. {
  788.     XDestroyImage(image);
  789.     XClearWindow(xd->display, xd->window);
  790. }
  791.  
  792. /* ====================================================================== */
  793. /* GetImage: Sizepair => (width, height)     */
  794. /*          size     => area = width * height       */
  795.  
  796. int   GetImage(xd, xp)       
  797. XD *xd;
  798. XParams *xp;
  799. {
  800.     int width, height;
  801.     int dst_x = 0, dst_y = 0;
  802.  
  803.     width  = xp->sizepair->s1;
  804.     height = xp->sizepair->s2;
  805.     for (i = 0; i < xp->itns; i++) {
  806.     XDestroyImage(image);
  807.     image =XGetImage(xd->display, xd->window, 
  808.             0, 0, width, height, ~0, ZPixmap);
  809.     dst_x ++; dst_y ++;
  810.     if ((dst_x + width ) > DISPWIDTH ) dst_x = 0;
  811.     if ((dst_y + height) > DISPHEIGHT) dst_y = 0;
  812.     }
  813. }
  814.  
  815. int i_GetImage(xd, xp)       
  816. XD *xd;
  817. XParams *xp;
  818. {
  819.     i_PutImage(xd, xp);
  820. }
  821.  
  822. int c_GetImage(xd, xp)       
  823. XD *xd;
  824. XParams *xp;
  825. {
  826.     XClearWindow(xd->display, xd->window);
  827. }
  828.  
  829. /* ====================================================================== */
  830. /* The following is a convenience function for filling the window with junk */
  831. #define NUMPOINTS 100
  832.  
  833. RandomFill (xd, xp)
  834. XD *xd;
  835. XParams *xp;
  836. {
  837.     points = (XPoint *) malloc (NUMPOINTS * sizeof(XPoint));
  838.     for (i = 0; i < NUMPOINTS; i ++) {
  839.     points[i].x = rand() % DISPWIDTH;
  840.     points[i].y = rand() % DISPHEIGHT;
  841.     }
  842.     XDrawPoints(xd->display, xd->window, xp->gc,
  843.     points, NUMPOINTS, CoordModeOrigin);
  844.     XDrawLines(xd->display, xd->window, xp->gc, 
  845.     points, NUMPOINTS, CoordModeOrigin);
  846.     free(points);
  847. }
  848.